package com.management.demo.common;

import cn.dev33.satoken.stp.StpInterface;
import com.management.demo.domain.Menu;
import com.management.demo.service.UserService;
import com.management.demo.vo.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SaTokenPermission implements StpInterface {

    @Autowired
    private UserService userService;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        Integer userId = Integer.parseInt(String.valueOf(loginId));
        List<Menu> menuList = userService.getACLListByUserId(userId);
        return menuList.stream().map(Menu::getAcl).toList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        Integer userId = Integer.parseInt(String.valueOf(loginId));
        List<RoleVO> roleList = userService.getRoleListByUserId(userId);
        return roleList.stream().map(RoleVO::getTag).toList();
    }
}
